package mysql

import "gorm.io/gorm"

type Coupon struct {
	gorm.Model
	UserId     int    `gorm:"type:int;comment:用户Id"`
	CouponName string `gorm:"type:varchar(20);comment:优惠卷类型名称"`
}

func (Coupon) TableName() string {
	return "coupon"
}

func (c *Coupon) Add() error {
	return DB.Create(&c).Error
}

func (c *Coupon) Find(id int) (result Coupon, err error) {
	err = DB.Where("user_id=?", id).Find(&result).Error
	if err != nil {
		return Coupon{}, err
	}
	return result, nil
}
